package com.medata.utils;

import com.medata.dataObject.Databaselist;
import com.medata.vo.SysMenu;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ：zb
 * @date ：Created in 2019/5/16 0016 15:50
 * @description：
 */
public class MenuUtil {

    public static List<SysMenu> getEditorMenu(String perfix,List<Databaselist> databaselists){
        List<SysMenu> sLists=new ArrayList<>();
        SysMenu fathMenu=new SysMenu();
        fathMenu.setName("资料编辑");
        fathMenu.setType(0);
        fathMenu.setId(1);
        fathMenu.setUrl("/");
        fathMenu.setSort(0);
        fathMenu.setParentId(0);
        sLists.add(fathMenu);
        int sort=1;
        //新闻管理
        SysMenu fathMenu2=new SysMenu();
        fathMenu2.setName("新闻管理");
        fathMenu2.setType(0);
        fathMenu2.setId(2);
        fathMenu2.setUrl("/");
        fathMenu2.setSort(0);
        fathMenu2.setParentId(0);
        sLists.add(fathMenu2);
        SysMenu sysMenu3=new SysMenu();
        sysMenu3.setId(666);
        sysMenu3.setType(2);
        sysMenu3.setName("新闻编辑");
        sysMenu3.setUrl(perfix+"/editor/newsManager");
        sysMenu3.setParentId(2);
        sysMenu3.setSort(sort);
        sort++;
        sLists.add(sysMenu3);
        //概览
//        SysMenu sysMenu3=new SysMenu();
//        sysMenu3.setId(666);
//        sysMenu3.setType(2);
//        sysMenu3.setName("统计概览");
//        sysMenu3.setUrl("/editor/totalManager");
//        sysMenu3.setParentId(1);
//        sysMenu3.setSort(sort);
//        sort++;
//        sLists.add(sysMenu3);
        //主表
//        SysMenu sysMenu2=new SysMenu();
//        sysMenu2.setId(666);
//        sysMenu2.setType(2);
//        sysMenu2.setName("主表");
//        sysMenu2.setUrl("/editor/main");
//        sysMenu2.setParentId(1);
//        sysMenu2.setSort(sort);
//        sort++;
//        sLists.add(sysMenu2);
        if (databaselists!=null&&databaselists.size()>0){
            for (Databaselist databaselist:databaselists){
                SysMenu sysMenu=new SysMenu();
                sysMenu.setId(666);
                sysMenu.setType(2);
                sysMenu.setName(databaselist.getDbtitle());
                sysMenu.setUrl(perfix+"/editor/solrSearch/"+databaselist.getDbid()+"/1");
                sysMenu.setParentId(1);
                sysMenu.setSort(sort);
                sort++;
                sLists.add(sysMenu);
            }
        }
        return sLists;
    }

    public static List<SysMenu> getAdminMenu(String perfix){
        List<SysMenu> sLists=new ArrayList<>();
        sLists.add(getSysMenu("用户管理",0,1,"/",1,0));
        sLists.add(getSysMenu("用户管理",2,11,perfix+"/admin/usersget/1/10",11,1));
        sLists.add(getSysMenu("IP管理",0,2,"/",2,0));
        sLists.add(getSysMenu("IP区域管理",2,22,"admin/areaFilter/1",21,2));
        sLists.add(getSysMenu("IP限制管理",2,22,"admin/LockIPsget/1",23,2));
        sLists.add(getSysMenu("OA管理",2,22,"admin/oaManager//1",24,2));
//        sLists.add(getSysMenu("OAI访问IP管理",0,22,"/",3,2));
        sLists.add(getSysMenu("IP黑名单",2,221,"admin/blackIPget/1",221,2));
        sLists.add(getSysMenu("日志管理",0,3,"/editor",3,0));
        sLists.add(getSysMenu("日志配置",2,33,perfix+"/admin//actiondefsGet",31,3));

        //获取时间
        DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDateTime nowTime = LocalDateTime.now(ZoneOffset.of("+8"));
        String t1 = nowTime.format(formatter);
        LocalDateTime oldTime = nowTime.minusDays(8);
        String t2 = oldTime.format(formatter);
        String logmakedocumentUrl=perfix+"/admin/logmakeDocumentGet/1/"+t2+"/"+t1+"/创建元数据"+"/1/1";
        String logsearchUrl=perfix+"/admin/logsearchGet/1/"+t2+"/"+t1+"/简单检索"+"/1/1/1";
        String logdetailUrl=perfix+"/admin/logdetailGet/1/"+t2+"/"+t1+"/1"+"/1/1";
        String logloginUrl=perfix+"/admin/logloginGet/1/"+t2+"/"+t1+"/IP登陆"+"/1/1";
        String logdispUrl=perfix+"/admin/logdispprjGet/1/"+t2+"/"+t1+"/全文访问日志"+"/1/1/1";
        String zlVisitUrl=perfix+"/admin/zlVisit/"+t2+"/"+t1;
        sLists.add(getSysMenu("资源日志",2,331,logmakedocumentUrl,32,3));
        sLists.add(getSysMenu("浏览日志",2,332,logdetailUrl,33,3));
        sLists.add(getSysMenu("检索日志",2,333,logsearchUrl,34,3));
        sLists.add(getSysMenu("登入日志",2,334,logloginUrl,35,3));
        sLists.add(getSysMenu("全文日志",2,335,logdispUrl,36,3));
        sLists.add(getSysMenu("资源汇总统计",2,336,perfix+"/admin/zlCount",37,3));
        sLists.add(getSysMenu("库访问日志",2,337,zlVisitUrl,38,3));
//        sLists.add(getSysMenu("系统管理",0,4,"/",4,0));
//        sLists.add(getSysMenu("系统设置",2,44,"/editor",41,4));
//系统设置
        sLists.add(getSysMenu("系统设置",0,4,"/",4,0));
        sLists.add(getSysMenu("系统设置",2,41,perfix+"/admin/sysSet",41,4));

        return sLists;
    }

    public static SysMenu getSysMenu(String name,Integer type,Integer id,String url,Integer sort,Integer pid){
        SysMenu fathMenu=new SysMenu();
        fathMenu.setName(name);
        fathMenu.setType(type);
        fathMenu.setId(id);
        fathMenu.setUrl(url);
        fathMenu.setSort(sort);
        fathMenu.setParentId(pid);
        return fathMenu;
    }

    public static List<SysMenu> getAuditorMenu(String perfix,List<Databaselist> databaselists){
        List<SysMenu> sLists=new ArrayList<>();
        SysMenu fathMenu=new SysMenu();
        fathMenu.setName("资料编辑");
        fathMenu.setType(0);
        fathMenu.setId(1);
        fathMenu.setUrl("/");
        fathMenu.setSort(0);
        fathMenu.setParentId(0);
        sLists.add(fathMenu);
        int sort=1;
        if (databaselists!=null&&databaselists.size()>0){
            for (Databaselist databaselist:databaselists){
                SysMenu sysMenu=new SysMenu();
                sysMenu.setId(666);
                sysMenu.setType(2);
                sysMenu.setName(databaselist.getDbtitle());
                sysMenu.setUrl(perfix+"/Auditor/solrSearch/"+databaselist.getDbid()+"/1");
                sysMenu.setParentId(1);
                sysMenu.setSort(sort);
                sort++;
                sLists.add(sysMenu);
            }
        }
        return sLists;
    }
}
